/*
     Copyright 2007 Joseph M. Ferner

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System.Collections.Generic;
using System.Net.Sockets;
using OpenServers.Net.Common.Listener;
using OpenServers.Net.Common.Socket;
using OpenServers.Net.Common.State;

namespace OpenServers.Net.Common {
    /// <summary>
    /// delegate for initializing a state object.
    /// </summary>
    public delegate void InitializeStateDelegate(IServer server, IState state);

    /// <summary>
    /// Base interface for all servers.
    /// </summary>
    public interface IServer {
        /// <summary>
        /// Starts the server.
        /// </summary>
        void Start();

        /// <summary>
        /// Stops the servers.
        /// </summary>
        void Stop();

        /// <summary>
        /// Gets the list of listeners.
        /// </summary>
        IList<IListener> Listeners { get; }

        /// <summary>
        /// Checks if server is started.
        /// </summary>
        bool Started { get; }

        /// <summary>
        /// Creates a state object.
        /// </summary>
        /// <param name="listener">the listener who called this method.</param>
        /// <param name="clientSocket">The client socket.</param>
        /// <returns></returns>
        IState CreateState(IListener listener, ISocket clientSocket);

        /// <summary>
        /// Initializes the state object.
        /// </summary>
        event InitializeStateDelegate InitializeState;

        /// <summary>
        /// Fires the initialize state events.
        /// </summary>
        void FireInitializeState(IState state);
    }
}
